package com.lyf.juc.learn.sggadvance.create;

import org.junit.Test;

import java.util.concurrent.TimeUnit;

/**
 * @author LYF
 * @date 2022/6/28
 */
public class ThreadCreateAnalysis {
    /*
    start()- 启动 -- start0--native方法
    关于C源码分析：OpenJdk下载地址
    ：https://jdk.java.net/java-se-ri/8-MR3
     */
    @Test
    public void test0(){

    }

    public static void main(String[] args) throws Exception{
        Thread t = new Thread(()->{
            System.out.println(Thread.currentThread().isDaemon() ?"守护线程":"用户线程");
            String threadName = Thread.currentThread().getName();
            for(;;){
                System.out.println(threadName+":::"+System.currentTimeMillis());
                try {
                    TimeUnit.SECONDS.sleep(2);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        // 守护线程--当守护的线程结束（此DEMO即Main线程），则结束
        t.setDaemon(true);
        t.start();

        TimeUnit.SECONDS.sleep(3);
        System.out.println("Main exit...");
    }
}
